﻿namespace OleDbDAL.Systems
{
    using DBUtility;
    using IDal.Systems;
    using Model.Systems;
    using System;
    using System.Data;
    using System.Text;

    public class PopdomValueApp : IPopdomValue
    {
        private string dbname = "Systems";

        public void Add(PopdomValueEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_PopdomValue(");
            builder.Append("PopTempId,PopdomName,PopdomAction,PopdomValue");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.PopTempId + ",");
            builder.Append("'" + model.PopdomName + "',");
            builder.Append("'" + model.PopdomAction + "',");
            builder.Append("'" + model.PopdomValue + "'");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int PopdomId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from T_PopdomValue ");
            builder.Append(" where PopdomId=" + PopdomId);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_PopdomValue ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by PopdomId ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "PopdomId", "T_PopdomValue", swhere);
        }

        public PopdomValueEnt GetModel(int PopdomId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select PopdomId,PopTempId,PopdomName,PopdomAction,PopdomValue from T_PopdomValue ");
            builder.Append(" where PopdomId=" + PopdomId);
            PopdomValueEnt ent = new PopdomValueEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.PopdomId = PopdomId;
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["PopTempId"].ToString() != "")
                {
                    ent.PopTempId = int.Parse(table.Rows[0]["PopTempId"].ToString());
                }
                ent.PopdomName = table.Rows[0]["PopdomName"].ToString();
                ent.PopdomAction = table.Rows[0]["PopdomAction"].ToString();
                ent.PopdomValue = table.Rows[0]["PopdomValue"].ToString();
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_PopdomValue ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "PopdomId");
        }

        public void Update(PopdomValueEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_PopdomValue set ");
            builder.Append("PopTempId=" + model.PopTempId + ",");
            builder.Append("PopdomName='" + model.PopdomName + "',");
            builder.Append("PopdomAction='" + model.PopdomAction + "',");
            builder.Append("PopdomValue='" + model.PopdomValue + "'");
            builder.Append(" where PopdomId=" + model.PopdomId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

